# demo06_gen.py  生成器表达式 1~5
# 生成器: 小内存处理大数据量的一种方式(延迟加载)
list01 = [i for i in range(1, 6)]
print(list01)
# 生成器表达式
gen = (i for i in range(1, 6))  # 1~5
print(gen, type(gen))  # <class 'generator'>
# 1.for  2.__next__   生成器中的元素只能获取一遍
print(gen.__next__())  # 1
print(gen.__next__())  # 2
for item in gen:
    print("for:", item)  # 3 4 5
# print("last:", gen.__next__())  # StopIteration
# >>> sum([i for i in range(1,500000000)])
# 已杀死
# >>> sum((i for i in range(1,800000000)))
# 319999999600000000